package com.farm.cropper.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.farm.common.annotation.Log;
import com.farm.common.core.controller.BaseController;
import com.farm.common.core.domain.AjaxResult;
import com.farm.common.enums.BusinessType;
import com.farm.cropper.domain.Cropper;
import com.farm.cropper.service.ICropperService;
import com.farm.common.utils.poi.ExcelUtil;
import com.farm.common.core.page.TableDataInfo;

/**
 * 农作物管理Controller
 * 
 * @author yd
 * @date 2024-03-17
 */
@RestController
@RequestMapping("/cropper/cropper")
public class CropperController extends BaseController
{
    @Autowired
    private ICropperService cropperService;

    /**
     * 查询农作物管理列表
     */
    @PreAuthorize("@ss.hasPermi('cropper:cropper:list')")
    @GetMapping("/list")
    public TableDataInfo list(Cropper cropper)
    {
        startPage();
        List<Cropper> list = cropperService.selectCropperList(cropper);
        return getDataTable(list);
    }

    /**
     * 导出农作物管理列表
     */
    @PreAuthorize("@ss.hasPermi('cropper:cropper:export')")
    @Log(title = "农作物管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Cropper cropper)
    {
        List<Cropper> list = cropperService.selectCropperList(cropper);
        ExcelUtil<Cropper> util = new ExcelUtil<Cropper>(Cropper.class);
        util.exportExcel(response, list, "农作物管理数据");
    }

    /**
     * 获取农作物管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('cropper:cropper:query')")
    @GetMapping(value = "/{cropperId}")
    public AjaxResult getInfo(@PathVariable("cropperId") Long cropperId)
    {
        return success(cropperService.selectCropperByCropperId(cropperId));
    }

    /**
     * 新增农作物管理
     */
    @PreAuthorize("@ss.hasPermi('cropper:cropper:add')")
    @Log(title = "农作物管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Cropper cropper)
    {
        return toAjax(cropperService.insertCropper(cropper));
    }

    /**
     * 修改农作物管理
     */
    @PreAuthorize("@ss.hasPermi('cropper:cropper:edit')")
    @Log(title = "农作物管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Cropper cropper)
    {
        return toAjax(cropperService.updateCropper(cropper));
    }

    /**
     * 删除农作物管理
     */
    @PreAuthorize("@ss.hasPermi('cropper:cropper:remove')")
    @Log(title = "农作物管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{cropperIds}")
    public AjaxResult remove(@PathVariable Long[] cropperIds)
    {
        return toAjax(cropperService.deleteCropperByCropperIds(cropperIds));
    }
}
